﻿using System;

namespace TempEmployees.BLL.Validations
{
    public class BirthDate
    {
        private DateTime m_birthDate;

        public DateTime Date { get { return m_birthDate; } }

        public BirthDate(DateTime birthDate)
        {
            m_birthDate = birthDate;
            if (!IsValid(m_birthDate)) throw new ValidationErrorException();
        }

        public static bool IsValid(DateTime birthDate)
        {
            if (birthDate == null || DateTime.Now.Year - birthDate.Year < 18 || DateTime.Now.Year - birthDate.Year > 100)
                return false;
            return true;
        }

        public static bool IsValid(object data)
        {
            if (!DateField.IsValid(data)) return false;
            return IsValid(DateTime.Parse(data.ToString()));
        }
    }
}